package com.macro.mall.common.validated;

import cn.hutool.core.util.PhoneUtil;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.util.StringUtils;

import java.util.regex.Pattern;

/**
 * @author: TuDou
 * @create: 2024-10-22 14:07
 **/
public class PhoneValidator implements ConstraintValidator<Phone, String> {

    @Override
    public void initialize(Phone constraintAnnotation) {

    }

    @Override
    public boolean isValid(String phone, ConstraintValidatorContext context) {
        //空字符串有拦截了  不然会冲突
        return StringUtils.isEmpty(phone) || PhoneUtil.isPhone(phone);
    }
}
